package cn.zn.modules.money.his.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.zn.modules.money.enums.MoneyTypeEnum;
import cn.zn.modules.money.his.entity.MoneyInfoFreezs;
import cn.zn.modules.money.his.entity.QMoneyInfoFreezs;
import cn.zn.modules.money.his.entity.dto.MoneyInfoFreezsDTO;
import cn.zn.modules.money.his.entity.vo.MoneyInfoFreezsVO;
import cn.zn.modules.money.his.repository.MoneyInfoFreezsRepository;
import cn.zn.modules.money.his.service.MoneyInfoFreezsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;


@Service("moneyInfoFreezsService")
public class MoneyInfoFreezsServiceImpl implements MoneyInfoFreezsService {

    @Autowired
    private MoneyInfoFreezsRepository moneyInfoFreezsRepository;

    @Override
    public List<MoneyInfoFreezsVO> findFreezs(MoneyInfoFreezsDTO moneyInfoFreezsDTO) {
        QMoneyInfoFreezs qMoneyInfoFreezs = QMoneyInfoFreezs.moneyInfoFreezs;
        Iterator<MoneyInfoFreezs> moneyInfoFreezsIterator = moneyInfoFreezsRepository.findAll(qMoneyInfoFreezs.ap.eq(moneyInfoFreezsDTO.getAp())
                .and(qMoneyInfoFreezs.moneyTypeCode.eq(moneyInfoFreezsDTO.getMoneyTypeCode()))
                .and(qMoneyInfoFreezs.projectCode.eq(moneyInfoFreezsDTO.getProjectCode()))
                .and(qMoneyInfoFreezs.cateCode.eq(moneyInfoFreezsDTO.getCateCode()))).iterator();
        List<MoneyInfoFreezsVO> moneyInfoFreezsVOS = CollUtil.newArrayList();
        MoneyInfoFreezsVO moneyInfoFreezsVO;
        while (moneyInfoFreezsIterator.hasNext()) {
            MoneyInfoFreezs moneyInfoFreezs = moneyInfoFreezsIterator.next();
            moneyInfoFreezsVO = new MoneyInfoFreezsVO();
            BeanUtils.copyProperties(moneyInfoFreezs, moneyInfoFreezsVO);
            moneyInfoFreezsVO.setMoneyTypeName(MoneyTypeEnum.findByCode(moneyInfoFreezs.getMoneyTypeCode()).getName());
            moneyInfoFreezsVOS.add(moneyInfoFreezsVO);
        }
        return moneyInfoFreezsVOS;
    }
}